package com.atguigu.ssyx;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @作者:胡树苑
 * @时间:2025/9/21 20:06
 */
//串行化
public class CompletableFutureDemo4 {
    public static void main(String[] args) {
        //创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        System.out.println("main begin");
        CompletableFuture<Integer> futureA = CompletableFuture.supplyAsync(() -> {
            int value =1024;
            System.out.println("任务1:" + value);
            return value;
        }, executorService);
        CompletableFuture<Integer> futureB = futureA.thenApplyAsync((res) -> {
            System.out.println("任务2:"+res);
            return res;
        }, executorService);
        CompletableFuture<Void> futureC = futureA.thenRunAsync(() -> {
            System.out.println("任务3");
        });
        System.out.println("main end");
    }
}
